#include "mainwindow.h"

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
{
    this->setGeometry(0, 0, 800, 480);

    /* 实例化水平滑动条对象*/
    horizontalSlider = new QSlider(Qt::Horizontal, this);
    /* 设置显示的位置与大小 */
    horizontalSlider->setGeometry(250, 100, 200, 20);
    /* 设置值范围 */
    horizontalSlider->setRange(0, 100);

    verticalSlider = new QSlider(Qt::Vertical, this);
    verticalSlider->setGeometry(200, 50, 20, 200);
    verticalSlider->setRange(0, 100);

    label = new QLabel(this);
    label->setGeometry(250, 200, 100, 20);

    connect(horizontalSlider, SIGNAL(valueChanged(int)), this,
            SLOT(horizontalSliderValueChanged(int)));
    connect(verticalSlider, SIGNAL(valueChanged(int)), this,
            SLOT(verticalSliderValueChanged(int)));

}

MainWindow::~MainWindow()
{
}

void MainWindow::horizontalSliderValueChanged(int val)
{
    verticalSlider->setSliderPosition(val);
    QString str = "滑动条值：" + QString::number(val);
    label->setText(str);
}

void MainWindow::verticalSliderValueChanged(int val)
{
    horizontalSlider->setSliderPosition(val);
}
